package com.xidian.zhiancloud.controller.dangerWorkTicket.workManager;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.qo.dangerWorkTicket.WorkTicketQO;
import com.xidian.zhiancloud.service.dangerWorkTicket.WorkManager.MyDelayApplicationService;
import com.xidian.zhiancloud.vo.dangerWorkTicket.MyDelayApplicationDTOVO;
import com.xidian.zhiancloud.vo.dangerWorkTicket.WorkTicketVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 第二页作业管理 - 我的延期申请，有增加、删除、查看（与申请延期页面一致）、列表查找
 * 新建class myDelay***，保存当前状态（全部、待审批、已审批、已拒绝）。
 * 通过id向前端返回数据大页面的数据。查看时需要给出“审批意见表”t_approve中匹配id的所有数据。
 */

@RestController
@RequestMapping("/MyDelayApplication")
public class MyDelayApplicationController extends BaseController {
    @Autowired
    private MyDelayApplicationService myDelayApplicationService;

    /**
     *  根据id查看作业票
     *
     * @param id
     */
    @GetMapping("/getById")
    public ResultDTO<MyDelayApplicationDTOVO> getById(@RequestParam("id") Long id) {
        return ResultDTO.successOf(myDelayApplicationService.getVOById(id), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 列表查询
     *
     */
    @GetMapping("/getListByQO")
    public ResultDTO<IPage<WorkTicketVO>> getListByQO(WorkTicketQO workTicketQO) {
        if(workTicketQO.getCurrent() == null || workTicketQO.getSize() == null) {
            return ResultDTO.errorOf(GeneralResponseEnums.REQUEST_ERROR);
        }
        workTicketQO.setCreatorId(getSessionUserid());
        workTicketQO.setCompanyId(getSessionUserCompanyId());

        return ResultDTO.successOf(myDelayApplicationService.getListByQO(workTicketQO), GeneralResponseEnums.SUCCESS);
    }


}
